<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 2. 准备容器 -->
    <div id="app">
      <!-- v-model 表单双向绑定 ,就是数据和视图同时更新 -->
      <h1>v-model 表单双向绑定</h1>
      <label>用户：<input type="text" v-model="username" /> </label>
      <br />
      <br />
      <label>密码：<input type="password" v-model="password" /></label>
      <br />
      <br />
      <button @click="submit()">登录</button>
      <button @click="reset()">重置</button>
      <p>数据:{{ username }}</p>
      <p>数据:{{ password }}</p>
    </div>

    <!-- 1. 导入 vue.js -->
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

    <script>
      // 3. 创建 Vue 实例对象
      const app = new Vue({
        // 容器
        el: "#app",
        // 数据
        data: {
          username: "",
          password: "",
        },
        // 事件处理函数
        methods: {
          submit() {
            alert(`登录的数据为${this.username},${this.password}`);
          },
          reset() {
            this.username = "";
            this.password = "";
          },
        },
      });
    </script>
  </body>
</html>